package com.huanghwh.demo.event.listener;

import cn.hutool.log.StaticLog;
import com.huanghwh.demo.event.entity.OrderMessage;
import org.springframework.context.ApplicationListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @Author: huanghwh
 * @Date: 2023/03/26 下午8:45
 * @Description: 订单消费者1：日志记录
 */
@Service
public class OrderLogListener implements ApplicationListener<OrderEvent> {
    
    //@EventListener(OrderEvent.class) //可使用注解或实现ApplicationListener，二选一
    @Async("myThreadExecutor") // 异步执行
    @Override
    public void onApplicationEvent(OrderEvent orderEvent) {
        OrderMessage source = (OrderMessage) orderEvent.getSource();
        StaticLog.info("异步消费者1:日志记录，订单号{}", source.getOrderNo());
    }
    
}
